<?php
/**
 * Created by PhpStorm.
 * User: qingyun
 * Date: 2019/5/15
 * Time: 9:17 PM
 */

namespace app\admin\controller;

use app\admin\controller\Base;

class Company extends Base
{
        public function lists(){

            $list = \think\Db::table('company')->paginate(3);

            $this->assign('list',$list);

            return $this->fetch();

        }

        public function del(){

            $company_id = $this->request->param('id');

            if (empty($company_id)){
                $this->error('非法操作');
            }

            if (\think\Db::table('company')->where('id',$company_id)->delete()){

                $this->success('删除成功');
            }else{
                $this->error('非法操作');
            }
        }

        public function mod(){

           if ($this->request->isGet()){

               $company_id = $this->request->param('id');

               if (empty($company_id)){
                   $this->error('非法操作');
               }
               $info = \think\Db::table('company')->where('id',$company_id)->find();

               if (empty($info)){
                   $this->error('非法操作');
               }
               $this->assign('info',$info);

               return $this->fetch();
           }

           if ($this->request->isPost()){

               $data = $this->request->only(['name','address','phone','sort','scale','sex_ratio','uid','introduce']);
               $id=$this->request->param('id');
               //todo 数据验证


               if (\think\Db::table('company')->where('id',$id)->update($data)){

                   $this->success('修改成功',url('admin/company/lists'));
               }else{
                   $this->error('修改失败');
               }


           }



        }



}











